<template>
<!-- 横向导航条 -->
  <nav class="aui-navbar" :class="`aui-navbar--${$store.state.navbarLayoutType}`">
    <div class="aui-navbar__header">
      <h1 class="aui-navbar__brand" @click="$router.push({ name: 'home' })">
        <a class="aui-navbar__brand-lg" href="javascript:;">党建“驿站”</a>
      </h1>
    </div>
    <div class="aui-navbar__body">
      <el-menu class="aui-navbar__menu mr-auto" mode="horizontal">
        <!-- 收起列表 -->
        <el-menu-item index="1" @click="$store.state.sidebarFold = !$store.state.sidebarFold">
          <svg class="icon-svg aui-navbar__icon-menu aui-navbar__icon-menu--switch" aria-hidden="true"><use xlink:href="#icon-outdent"></use></svg>
        </el-menu-item>
        <!-- <el-menu-item index="2" @click="refresh()">
          <svg class="icon-svg aui-navbar__icon-menu aui-navbar__icon-menu--refresh" aria-hidden="true"><use xlink:href="#icon-sync"></use></svg>
        </el-menu-item> -->
      </el-menu>
      <el-menu class="aui-navbar__menu" mode="horizontal">
        <!-- <el-menu-item index="2">
          <a href="https://www.renren.io/" target="_blank">
            <svg class="icon-svg aui-navbar__icon-menu" aria-hidden="true"><use xlink:href="#icon-earth"></use></svg>
          </a>
        </el-menu-item> -->
        <!-- <el-menu-item index="2">
          <a href="https://gitee.com/renrenio/renren-security" target="_blank">
            <svg class="icon-svg aui-navbar__icon-menu" aria-hidden="true"><use xlink:href="#gitee"></use></svg>
          </a>
        </el-menu-item> -->
        <!-- 全屏 -->
        <!-- <el-menu-item index="4" @click="fullscreenHandle()">
          <svg class="icon-svg aui-navbar__icon-menu" aria-hidden="true"><use xlink:href="#icon-fullscreen"></use></svg>
        </el-menu-item> -->
        <!-- 用户信息 -->
        <el-menu-item @click="getmyinfo(modifymyinfoId,mytoken)" index="5" class="aui-navbar__avatar">
          <el-dropdown placement="bottom" :show-timeout="0">
            <span class="el-dropdown-link">
              <img :src="photograph">
              <span>{{username}}</span>
              <i class="el-icon-arrow-down"></i>
            </span>
            <!-- 修改密码和退出登录 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item>
              <el-dropdown-item @click.native="logoutHandle()">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-menu-item>
      </el-menu>
    </div>
    <!-- 弹窗, 修改密码 -->
    <update-password v-if="updatePasswordVisible" ref="updatePassword"></update-password>
    <!-- 我的详细信息 -->
    <userDetail @person="person" ref="myDetil" v-if="showmydetailed" @toclose="cancel(detail)"></userDetail>
  </nav>
</template>
<script>
import screenfull from 'screenfull'
import UpdatePassword from './main-navbar-update-password'
import { clearLoginInfo } from '@/utils'
import userDetail from "./modules/sys/user_detailed.vue"
import transfer from "../assets/js/transfer";
export default {
  components:{
    userDetail,UpdatePassword
  },
  inject: ['refresh'],
  data () {
    return {
      updatePasswordVisible: false,
      messageTip: false,
      username:"",//用户姓名
      photograph:"",//当前用户的头像
      modifymyinfoId:1,//打开用户详细信息的状态。0：可修改信息；1：不可修改信息
      showmydetailed:false,//控制打开用户详细信息弹框
      mytoken:"",//用户token
    }
  },
  // components: {
  //   UpdatePassword
  // },
  mounted(){ 
    this.person()
    this.userinfo = JSON.parse(localStorage.getItem('userinfo'))
    // console.log()
    this.mytoken = localStorage.getItem('token')
    // transfer.$on('personinfo',()=> {
    //   this.personinfo();
    // })
  },
  methods: {
    // 全屏
    fullscreenHandle () {
      if (!screenfull.enabled) {
        return this.$message({
          message: "您的浏览器不支持此操作",
          type: 'warning',
          duration: 500
        })
      }
      screenfull.toggle()
    },
    getmyinfo(id,token){
      // console.log(id,token)
      this.showmydetailed = true
      this.$nextTick(() => {
        this.$refs.myDetil.init(id,token)
      })
    },
    // 修改密码
    updatePasswordHandle () {
      // 打开修改密码弹框
      this.updatePasswordVisible = true
      this.$nextTick(() => {
        this.$refs.updatePassword.init()
      })
    },
    // 退出
    logoutHandle () {//退出登录
      localStorage.clear()
      // localStorage.removeItem("userinfo");
      this.$store.state.contentTabs = this.$store.state.contentTabs.filter(item => item.name === 'home')
      this.$router.replace({ name: 'login'})
    },
    person(){//当前用户信息
      this.axios({
        headers:{'Authentication':localStorage.getItem('token')},
        method:"get",
        // url:"api/user/getCurrentUserInfo",
        url:"/user/getCurrentUserInfo",
        data:""
      }).then(res=>{
        if(res.data.code != 20001){
          return this.$message.error(res.data.msg)
        }
        // console.log(res)
        this.username = res.data.data.name
        this.photograph = res.data.data.photograph//头像
      })
    },
  }
}
</script>
